package com.workoutgrabber.model;

import java.util.List;

import org.jdom.Element;
import org.joda.time.DateTime;

public class Workout implements XMLable {
	private String name;
	private DateTime startDate, endDate;
	private List<Exercise> exercises;
	
	private Workout(String name, DateTime startDate, DateTime endDate, List<Exercise> exercises){
		this.name 		= name;
		this.startDate 	= startDate;
		this.endDate 	= endDate;
		this.exercises 	= exercises;
	}
	
	public static Workout getInstance(String name, DateTime startDate, DateTime endDate, List<Exercise> exercises){
		return new Workout(name, startDate, endDate, exercises);
	}

	@Override
	public Element getAsXML() {
		Element exerciseElement = new Element("workout");
		
		Element nameElement = new Element("name");
		nameElement.setText(this.name);
		
		Element startDateElement = new Element("startDate");
		startDateElement.setText(this.startDate.toString());

		Element endDateElement = new Element("endDate");
		endDateElement.setText(this.endDate.toString());

		Element exercisesElement = new Element("exercises");
		for (XMLable xml : exercises)
			exercisesElement.addContent(xml.getAsXML());
		
		exerciseElement.addContent(nameElement);
		exerciseElement.addContent(startDateElement);
		exerciseElement.addContent(endDateElement);
		exerciseElement.addContent(exercisesElement);
	
		return exerciseElement;
	}
}
